package com.zhny.project.count.ification.controller;

import com.zhny.common.utils.poi.ExcelUtil;
import com.zhny.framework.aspectj.lang.annotation.Log;
import com.zhny.framework.aspectj.lang.enums.BusinessType;
import com.zhny.framework.web.controller.BaseController;
import com.zhny.framework.web.domain.AjaxResult;
import com.zhny.framework.web.page.TableDataInfo;
import com.zhny.project.count.ification.domain.Ification;
import com.zhny.project.count.ification.service.IIficationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 算法分类Controller
 * 
 * @author lxh
 * @date 2019-09-24
 */
@Controller
@RequestMapping("/count/ification")
public class IficationController extends BaseController
{
    private String prefix = "count/ification";

    @Autowired
    private IIficationService ificationService;

    @RequiresPermissions("count:ification:view")
    @GetMapping()
    public String ification()
    {
        return prefix + "/ification";
    }

    /**
     * 查询算法分类列表
     */
    @RequiresPermissions("count:ification:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Ification ification)
    {
        startPage();
        List<Ification> list = ificationService.selectIficationList(ification);
        return getDataTable(list);
    }

    /**
     * 导出算法分类列表
     */
    @RequiresPermissions("count:ification:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Ification ification)
    {
        List<Ification> list = ificationService.selectIficationList(ification);
        ExcelUtil<Ification> util = new ExcelUtil<Ification>(Ification.class);
        return util.exportExcel(list, "ification");
    }

    /**
     * 新增算法分类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存算法分类
     */
    @RequiresPermissions("count:ification:add")
    @Log(title = "算法分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Ification ification)
    {
        return toAjax(ificationService.insertIfication(ification));
    }

    /**
     * 修改算法分类
     */
    @GetMapping("/edit/{ificationKey}")
    public String edit(@PathVariable("ificationKey") String ificationKey, ModelMap mmap)
    {
        Ification ification = ificationService.selectIficationById(ificationKey);
        mmap.put("ification", ification);
        return prefix + "/edit";
    }

    /**
     * 修改保存算法分类
     */
    @RequiresPermissions("count:ification:edit")
    @Log(title = "算法分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Ification ification)
    {
        return toAjax(ificationService.updateIfication(ification));
    }

    /**
     * 删除算法分类
     */
    @RequiresPermissions("count:ification:remove")
    @Log(title = "算法分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ificationService.deleteIficationByIds(ids));
    }

    /**
     * 校验ID
     */
    @PostMapping("/checkcontrollerId")
    @ResponseBody
    public String checkcontrollerId(Ification ification)
    {
        return ificationService.checkcontrollerId(ification);
    }

    /**
     * 校验Name
     */
    @PostMapping("/checkificationName")
    @ResponseBody
    public String checkificationName(Ification ification)
    {
        return ificationService.checkificationName(ification);
    }

}
